<template>
  <view class="goods-item">
    <!-- 左侧的盒子 -->
    <view class="goods-item-left">
      <radio :checked="item.goods_state" color="#C00000" v-if="showRadio" @click="radioClickHandler"></radio>
      <image :src="item.goods_small_logo || defaultPic" mode="" class="left-image"></image>
    </view>
    <!-- 右侧的盒子 -->
    <view class="goods-item-right">
      <view class="right-top">{{item.goods_name}}</view>
      <view class="aa">
        <view class="right-under">¥{{item.goods_price *( item.goods_count? item.goods_count:1)| tofixed}}

        </view>
        <uni-number-box min='1' :value='item.goods_count' @change="changeValue" v-if="numberBox" />
      </view>


    </view>
  </view>
</template>

<script>
  export default {
    name: "my-goods",
    props: {
      item: {
        type: Object,
        default: {}
      },
      showRadio: {
        type: Boolean,
        // 如果外界没有指定 show-radio 属性的值，则默认不展示 radio 组件
        default: false,
      },
      numberBox: {
        type: Boolean,
        default: false
      }
    },
    data() {
      return {
        defaultPic: 'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png',
      };
    },
    filters: {
      tofixed(num) {
        return Number(num).toFixed(2)
      }
    },
    methods: {
      radioClickHandler() {
        this.$emit('radio-change', {
          goods_id: this.item.goods_id,
          goods_state: !this.item.goods_state
        })
      },
      changeValue(e) {
        this.$emit('num-change', {
          goods_id: this.item.goods_id,
          // 商品的最新数量 +val是保证为number类型
          goods_count: +e
          // val+0 也可以保证是number类型
        })
      },
    }
  }
</script>

<style lang="scss">
  .goods-item {
    display: flex;
    padding: 10px 5px;
    border-bottom: 2px solid #dedede;

    .goods-item-left {
      margin-right: 5px;
      display: flex;
      align-items: center;

      .left-image {
        height: 100px;
        width: 100px;

      }
    }

    .goods-item-right {
      display: flex;
      flex-direction: column;
      justify-content: space-between;

      .right-top {
        font-size: 13px;
      }

      .aa {
        display: flex;
        justify-content: space-between;

        .right-under {
          display: flex;
          color: red;
        }

      }

    }
  }
</style>
